<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_service\Entity\ShusyServiceProduct;

/**
 * @OA\Schema(
 *   schema="ServiceItem",
 *   type="object",
 *   description="ServiceItem"
 * )
 */
class ServiceItem extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_service_product';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyServiceProduct) {
      $value = [
        /**
         * @OA\Property(
         *   property="name",
         *   type="string",
         *   description="名称",
         * ),
         */
        'name' => (string) $this->entity->name,
        /**
         * @OA\Property(
         *   property="amount",
         *   type="number",
         *   description="金额",
         * ),
         */
        'amount' => $this->convertYuan($this->entity->amount),
        /**
         * @OA\Property(
         *   property="image",
         *   type="string",
         *   description="封面图",
         * ),
         */
        'image' => (string) $this->getImage(file_load($this->entity->image)),
      ];
      $this->merge($value);
    }
  }

  protected function getImage($file) {
    return $this->imageStyleUrl('ProductItemImage', $file);
  }
}
